<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="jq/jquery1.9/jquery-1.9.0.js"></script>
    <style>
        .ball {
            width: 50px;
            height: 50px;
            background: hotpink;
            border-radius: 50%;
        }
    </style>
</head>

<body>
    <div class="ball ball1"></div>
    <div class="ball ball2"></div>
    <div class="ball ball3"></div>
    <div class="ball ball4"></div>
    <div class="ball ball5"></div>
    <br>
    <input type="button" value="move" onclick="doMove()">
    <script>

        function moveAll(ball,params,time){

            // jQuery对象.animate({样式名1:样式值1,样式名2:样式值2,},时间,回调函数);
            let p=new Promise(function(resolve,reject){
                ball.animate(params,time,resolve);
            });
            return p;
        }
        // function doMove() {
        //     //获取jQuery对象
        //     var ball1 = $(".ball1");
        //     var ball2 = $(".ball2");
        //     var ball3 = $(".ball3");
        //     var ball4 = $(".ball4");
        //     var ball5 = $(".ball5");
        //     let pro=moveAll(ball1,{"margin-left":"100px"},1000);
        //     pro.then(function(){
        //         return moveAll(ball2,{"margin-left":"200px"},1000); 
        //     }).then(function(){
        //         return  moveAll(ball3,{"margin-left":"300px"},1000);
        //     }).then(function(){
        //         return  moveAll(ball4,{"margin-left":"400px"},1000);
        //     }).then(function(){
        //         return  moveAll(ball5,{"margin-left":"500px"},1000);
        //     }).then(function(){
        //         return  moveAll(ball5,{"margin-left":"0px"},1000);
        //     }).then(function(){
        //         return  moveAll(ball4,{"margin-left":"0px"},1000);
        //     }).then(function(){
        //         return  moveAll(ball3,{"margin-left":"0px"},1000);
        //     }).then(function(){
        //         return  moveAll(ball2,{"margin-left":"0px"},1000);
        //     }).then(function(){
        //         return  moveAll(ball1,{"margin-left":"0px"},1000);
        //     });
        // }

      async  function doMove() {
            //获取jQuery对象
            var ball1 = $(".ball1");
            var ball2 = $(".ball2");
            var ball3 = $(".ball3");
            var ball4 = $(".ball4");
            var ball5 = $(".ball5");
            await moveAll(ball1,{"margin-left":"100px"},1000);
            await moveAll(ball2,{"margin-left":"200px"},1000);
            await moveAll(ball3,{"margin-left":"300px"},1000);
            await moveAll(ball4,{"margin-left":"400px"},1000);
            await moveAll(ball5,{"margin-left":"500px"},1000);
            await moveAll(ball5,{"margin-left":"0px"},1000);
            await moveAll(ball4,{"margin-left":"0px"},1000);
            await moveAll(ball3,{"margin-left":"0px"},1000);
            await moveAll(ball2,{"margin-left":"0px"},1000);
            await moveAll(ball1,{"margin-left":"0px"},1000);
          
        }
    </script>
</body>

</html>